package com.beikai.elasticsearch_demo.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.beikai.elasticsearch_demo.api.service.UserService;
import com.beikai.elasticsearch_demo.model.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2020-02-09 22:57:58
 */
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public User selectOne(Integer id) {
        return this.userService.queryById(id);
    }


    @GetMapping("/getInfo")
    public JSONObject getInfo(
            Integer num,
            Integer size
    ){
        return userService.getInfo(num,size);
    }
    @GetMapping("/getInfo2")
    public JSONObject getInfo2(
            Integer num,
            Integer size
    ){
        return userService.getInfo2(num,size);
    }

    @PostMapping("/addIndex")
    public JSONObject addIndex(
            String indexName
    ) throws IOException {
        return userService.addIndex(indexName);
    }

    @PostMapping("/addUser")
    public JSONObject addUser(){
        return userService.addUser();
    }

    @PostMapping("/deleteIndex")
    public JSONObject deleteIndex(
            String indexName
    ){
        return userService.deleteIndex(indexName);
    }

    @PostMapping("/updateIndexById")
    public JSONObject updateIndex(
            String id,
            String name,
            String address,
            String age,
            String message

    ){
        return userService.updateIndex(id,name,address,age,message);
    }

    @PostMapping("/batchAddDoc")
    public JSONObject batchAddDoc(){
        return userService.batchAddDoc();
    }



}